import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CategoryItem {
  late String id;
  late String name;
  late String icon;
  late String linkUrl;
  late int head_occupy = 0;

  CategoryItem(Map<String, dynamic> json) {
    id = "${json["id"]}";
    try {
      head_occupy = json['head_occupy'] as int;
    } catch (e) {
      head_occupy = 0;
    }
    this.name = json["name"] as String;
    this.icon = json["icon"] as String;
    this.linkUrl = '${json["path"]}';
  }

  Map<String, dynamic> get json {
    var result = Map<String, dynamic>();
    result["id"] = id;
    result["name"] = this.name;
    result["icon"] = this.icon;
    result["path"] = this.linkUrl;
    result["head_occupy"] = this.head_occupy;
    return result;
  }

  /// 百科使用的背景颜色。
  static List<Color> colorList = [
    Color(0xffFFF5E6),
    Color(0xffFFF5E6),
    Color(0xffFFF0EA),
    Color(0xffEAFCEF),
    Color(0xffEAFCEF),
    Color(0xffEAFCEF),
  ];
}

class CategoryAllData {
  late List<CategoryItem> position1;
  late List<CategoryItem> position2;

  CategoryAllData(Map<String, dynamic> json) {
    var list =
        json["position_1"] == null ? [] : json["position_1"] as List<dynamic>;
    position1 = list.map((e) => CategoryItem(e)).toList();
    var list2 =
        json["position_2"] == null ? [] : json["position_2"] as List<dynamic>;
    position2 = list2.map((e) => CategoryItem(e)).toList();
  }

  Map<String, dynamic> get json {
    return Map<String, dynamic>()
      ..["position_1"] = position1.map((e) => e.json).toList()
      ..["position_2"] = position2.map((e) => e.json).toList();
  }
}
